package github.kawaiior.yuanchuxiuzhen.common.gongfa.base;

import github.kawaiior.yuanchuxiuzhen.common.capability.entity.ManaPower;
import github.kawaiior.yuanchuxiuzhen.common.gongfa.GongFaBase;
import github.kawaiior.yuanchuxiuzhen.common.gongfa.IGongFa;
import github.kawaiior.yuanchuxiuzhen.core.init.GongFaInit;
import github.kawaiior.yuanchuxiuzhen.core.registry.ModCapability;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.common.util.LazyOptional;

public class YouShuiZhenJing extends GongFaBase {
    public YouShuiZhenJing(String itemName) {
        super(ManaPower.ManaRoot.WATER, 10000, GongFaInit.XUAN_SHUI_JUE, itemName);
    }


    @Override
    public void onPlayerLearn(PlayerEntity player, World world, ManaPower power) {

    }

    @Override
    public void onPlayerLearnFinish(PlayerEntity player, World world, ManaPower power) {
        // TODO: 添加效果
    }

    public static void onPlayerAttack(PlayerEntity player, World world, float amount, ManaPower power){
        learn(player, world, power, amount);
    }

    private static void learn(PlayerEntity player, World world, ManaPower power, float amount){
        if (!power.isLearningGongFa(GongFaInit.YOU_SHUI_ZHEN_JING)){
            return;
        }

        power.addGongFaExp(player, world, (int) amount);
    }

    // 效果
    public static void onPlayerTick(PlayerEntity player, ManaPower power){
        if (!power.isLearnedGongFa(GongFaInit.YOU_SHUI_ZHEN_JING)){
            return;
        }

        if (player.getHealth() < player.getMaxHealth()){
            player.heal(1F);
        }

        if (player.isPotionActive(Effects.WATER_BREATHING) && player.isPotionActive(Effects.NIGHT_VISION)){
            return;
        }

        player.addPotionEffect(new EffectInstance(Effects.WATER_BREATHING, 200000, 0));
        player.addPotionEffect(new EffectInstance(Effects.NIGHT_VISION, 200000, 0));
    }

}
